package gov.kqqzyyy.monkey.radiologyscreen.mytools;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import java.util.concurrent.TimeUnit;


import gov.kqqzyyy.monkey.radiologyscreen.R;
import gov.kqqzyyy.monkey.radiologyscreen.service.APIService;
import okhttp3.OkHttpClient;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
 * Created by Monkey on 2017/11/1.
 * Service工具类
 */

public class MyServiceUtil {

//    private static String mBaseUrl = "http://192.168.30.156:8081/api/API/";

    private static SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MyApplication.applicationContext);
    private static String serverAdd = sharedPreferences.getString("server_address", MyApplication.applicationContext.getString(R.string.default_server));
    private static String mBaseUrl = "http://" + serverAdd + "/api/API/";

    private static OkHttpClient client = new OkHttpClient.Builder()
            .connectTimeout(20, TimeUnit.SECONDS)
            .readTimeout(20, TimeUnit.SECONDS)
            .writeTimeout(20, TimeUnit.SECONDS)
            .build();
    private static Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(mBaseUrl)
            .client(client)
            .addConverterFactory(ScalarsConverterFactory.create())
            .build();

    private static APIService apiService = retrofit.create(APIService.class);

    public static Call<String> getSystemTimeCall() {
        return apiService.getSystemTime();
    }

    public static Call<String> getFSKPatients() {
        return apiService.getFSKPatients();
    }
}
